<?php
/*
	Begin Create Shortcode Generator Options
*/
add_action('admin_menu', 'shortcode_generator');
function shortcode_generator() {

  //add_submenu_page('functions.php', 'Shortcode Generator', 'Shortcode Generator', 'manage_options', 'shortcode_generator', 'shortcode_generator_options');
     	add_meta_box( 'shortcode_metabox', 'Shortcode Generator', 'shortcode_generator_options', 'page', 'normal', 'high' );
		add_meta_box( 'shortcode_metabox', 'Shortcode Generator', 'shortcode_generator_options', 'post', 'normal', 'high' );  
		add_meta_box( 'shortcode_metabox', 'Shortcode Generator', 'shortcode_generator_options', 'portfolio', 'normal', 'high' );  
}

function shortcode_generator_options() {

			     $color_array = array(
    				 'orange' => esc_html__('Orange','TT'),
    				 'red' => esc_html__('Red','TT'),
    				 'green' => esc_html__('Green','TT'),
    				 'blue' => esc_html__('Blue','TT'),
    				 'black' => esc_html__('Black','TT'),
    				 'yellow' => esc_html__('yellow','TT'),
    				 'purple' => esc_html__('Purple','TT'),
    				 'grey' => esc_html__('Grey','TT'),
				 );
	//Begin shortcode array
	$shortcodes = array(
		'h1' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => TRUE,
		),
		'h2' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => TRUE,
		),
		'h3' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => TRUE,
		),
		'h4' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => TRUE,
		),
		'h5' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => TRUE,
		),
		'h6' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => TRUE,
		),
		
		'p' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => TRUE,
		),
		'br' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => TRUE,
		),
		'container' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => TRUE,
		),
		'full_width' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => TRUE,
		),
		'clear' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => FALSE,
		),
		'button' => array(
			'attr' => array(
				   'color' => 'select',
				   'href' => 'text',
				   'lightbox_image' => 'text'
				   
			),
			'desc' => array(
				   'color' => esc_html__('Enter color(ex : BBDDFF)','TT'),
				   'href' => esc_html__('Enter link for button','TT'),
				   'lightbox' => esc_html__('Enter Lightbox for button','TT'),
			),
			'options' => array(
				   'color' => array(
				   'white' =>esc_html__('White','TT'),
				   'blue' =>esc_html__('Blue','TT'),
				   'yellow' =>esc_html__('Yellow','TT'),
				   'green' =>esc_html__('Green','TT'),
				   'grey' =>esc_html__('Grey','TT'),
				   'pink' =>esc_html__('Pink','TT'),
				   'purple' =>esc_html__('Purple','TT'),
				   'orange'=>esc_html__('Orange','TT'),
				   ),
			),
			'content' => TRUE,
		),
		'table' => array(
			'attr' => array(
				   'color' => 'select',
			),
			'desc' => array(
				   'color' => esc_html__('Select color style','TT'),
			),
			'options' => array(
				   'color' => array(
				   'light-gray' =>esc_html__('light-gray','TT'),
				   'dark-gray' =>esc_html__('dark-gray','TT'),
				   'light-green' =>esc_html__('light-green','TT'),
				   'light-orange' =>esc_html__('light-orange','TT'),
				   ),
			),
			'content' => TRUE,
		),
		'image' => array(
			'attr' => array(
				   'style' => 'select',
				   'width' => 'text',
				   'height' => 'text',
				   'src' => 'text',
				   'alt' => 'text',
				   
			),
			'desc' => array(
				   'style' => esc_html__('Float','TT'),
				   'width' => esc_html__('Enter width for image.(ex 480)','TT'),
				   'height' => esc_html__('Enter height for image.(ex 480)','TT'),
				   'src' => esc_html__('Enter image url','TT'),
				   'alt' => esc_html__('Enter Alt for image','TT'),
			),
			'options' => array(
				   'style' => array(
				   'left' =>esc_html__('left','TT'),
				   'right' =>esc_html__('right','TT'),
				   ),
			),
			'content' => FALSE,
		),
		'dropcap' => array(
			'attr' => array(
				   'style' => 'select',
			),
			'desc' => array(
				   'style' => esc_html__('Select a tyle','TT'),
			),
			'options' => array(
				   'style' => array(
				   'dropcap1' =>esc_html__('dropcap1','TT'),
				   'dropcap2' =>esc_html__('dropcap2','TT'),
				   'dropcap3' =>esc_html__('dropcap3','TT'),
				   ),
			),
			'content' => TRUE,
		),
		
		'one_half' => array(
			'attr' => array(
				   'style' => 'text',
			),
			'desc' => array(
				   'style' => esc_html__('If last on row please fill "last"','TT'),
			),
			'content' => TRUE,
		),
		'one_third' => array(
			'attr' => array(
				   'style' => 'text',
			),
			'desc' => array(
				   'style' => esc_html__('If last on row please fill "last"','TT'),
			),
			'content' => TRUE,
		),
		'two_third' => array(
			'attr' => array(
				   'style' => 'text',
			),
			'desc' => array(
				   'style' => esc_html__('If last on row please fill "last"','TT'),
			),
			'content' => TRUE,
		),
		'one_fourth' => array(
			'attr' => array(
				   'style' => 'text',
			),
			'desc' => array(
				   'style' => esc_html__('If last on row please fill "last"','TT'),
			),
			'content' => TRUE,
		),
		'three_fourth' => array(
			'attr' => array(
				   'style' => 'text',
			),
			'desc' => array(
				   'style' => esc_html__('If last on row please fill "last"','TT'),
			),
			'content' => TRUE,
		),
		'one_fifth' => array(
			'attr' => array(
				   'style' => 'text',
			),
			'desc' => array(
				   'style' => esc_html__('If last on row please fill "last"','TT'),
			),
			'content' => TRUE,
		),
		
		'info' => array(
			'attr' => array(
				   'style' => 'select',
			),
			'desc' => array(
				   'style' => esc_html__('Choice style for info','TT'),
			),
			'options' => array(
    				 'style' => array(
					 		 'info' => esc_html__('info','TT'),
					 		 'warning' => esc_html__('warning','TT'),
							 'error' => esc_html__('error','TT'),
							 'success' => esc_html__('success','TT'), 
					 ),
    			),

			'content' => TRUE,
		),
		'highlight' => array(
			'attr' => array(
				   'color' => 'select',
			),
			'desc' => array(
				   'color' => esc_html__('Choice color for hightlight','TT'),
			),
			'options' => array(
    				 'color' => array(
					 		 'white' => esc_html__('white','TT'),
					 		 'yellow' => esc_html__('yellow','TT'),
							 'black' => esc_html__('black','TT'),
							 'indianred' => esc_html__('indianred','TT'), 
							 'orange' => esc_html__('orange','TT'), 
							 'green' => esc_html__('green','TT'), 
							 'darkblue' => esc_html__('darkblue','TT'), 
							 'red' => esc_html__('red','TT'), 
							 'blue' => esc_html__('blue','TT'),
							 'brown' => esc_html__('brown','TT'),
					 ),
    			),
			'content' => TRUE,
		),
		'testimonial' => array(
			'attr' => array(
				   'title' => 'text',
				   'num_of_post' => 'text',
				   
			),
			'desc' => array(
				   'Title' => esc_html__('Set title for testimonial','TT'),
				   'num_of_post' => esc_html__('Set post will show for testimonial.Example : 3','TT'),
				   
			),
			'content' => FALSE,
		),
				
		'twitter' => array(
			'attr' => array(
				   'title' => 'text',
				   'username' => 'text',
				   'boxname' => 'text',
				   'count' => 'text',
				   
				   
			),
			'desc' => array(
				   'Title' => esc_html__('Set title for Twitter','TT'),
				   'num_of_post' => esc_html__('Set username.Example : manatstdio','TT'),
				   'boxname' => esc_html__('Set name of twitterbox.Example : twitter1','TT'),
				   'count' => esc_html__('Set num of twitter will be show.Example : 3','TT'),
			),
			'content' => FALSE,
		),
				
		'google_map' => array(
			'attr' => array(
				   'name' => 'text',
				   'type' => 'select',
				   'width' => 'text',
				   'height' => 'text',
				   'lat' => 'text',
				   'lon' => 'text',
				   'address' => 'text',
				   'popup' => 'text',
			),
			'desc' => array(
				   'name' => esc_html__('Set name for googlemap box','TT'),
				   'type' => esc_html__('Select a type','TT'),
				   'width' => esc_html__('set width for googlemap box','TT'),
				   'height' => esc_html__('set height for googlemap box','TT'),
				   'lat' => esc_html__('set latitude for googlemap box','TT'),
				   'lon' => esc_html__('set longitude for googlemap box','TT'),
				   'address' =>esc_html__('set address for googlemap box.Fill this input if you want using address','TT'),
				   'popup' => esc_html__('set popup for googlemap box.Fill this input if you want using address','TT'),
			),
			'options' => array(
				   'type' => array(
				   		  'ROADMAP' => esc_html('ROADMAP','TT'),
						  'SATELLITE' =>esc_html('SATELLITE','TT'),
				   ),
			),
			'content' => FALSE,
		),
		'video' => array(
			'attr' => array(
				   'style' => 'select',
				   'id' => 'text',
				   'width' => 'text',
				   'height' => 'text',
				   'embedcode' => 'text',
			),
			'desc' => array(
				   'style' => esc_html__('select video style','TT'),
				   'id' => esc_html__('Add ID of video','TT'),
				   'width' => esc_html__('Set width for video (Default : 640px)','TT'),
				   'height' => esc_html__('Set height for video (Default : 360px)','TT'),
				   'embedcode' => esc_html__('Paste embed code if you select Embed style','TT'),
			),
			'options' => array(
				   'style' => array(
				   		   'youtube' => esc_html('Youtube video','TT'),
						   'vimeo' => esc_html('vimeo video','TT'),
						   'embed' => esc_html('Embed code','TT'),
					),
			),
			'content' => FALSE,
		),
		'html5video' => array(
			'attr' => array(
				   'id' => 'text',
				   'image' => 'text',
				   'mp4' => 'text',
				   'webm' => 'text',
				   'ogg' => 'text',
				   'width' => 'text',
				   'height' => 'text',
				   
			),
			'desc' => array(
				   'id' => esc_html('Set ID of video box','TT'),
				   'image' => esc_html('Paste poster image','TT'),
				   'mp4' => esc_html('Paste mp4 file url','TT'),
				   'webm' => esc_html('Paste webm file url','TT'),
				   'ogg' => esc_html('Paste ogg file url','TT'),
				   'width' => esc_html('Set width of video','TT'),
				   'height' => esc_html('Set height of video','TT'),
			),
			'content' => FALSE,
		),
		'blockquote' => array(
			'attr' => array(),
			'desc' => array(),
			'content' => TRUE,
		),
		
		
	);

?>
<script>
jQuery(document).ready(function(){ 
	jQuery('#shortcode_select').change(function() {
  		var target = jQuery(this).val();
  		jQuery('.rm_section').css('display', 'none');
  		jQuery('#div_'+target).css('display', '');
	});	
	
	jQuery('.code_area').click(function() { 
		document.getElementById(jQuery(this).attr('id')).focus();
    	document.getElementById(jQuery(this).attr('id')).select();
	});
	
	jQuery('.button').click(function() { 
		var target = jQuery(this).attr('id');
		var gen_shortcode = '';
  		gen_shortcode+= '['+target;
  		
  		if(jQuery('#'+target+'_attr_wrapper .attr').length > 0)
  		{
  			jQuery('#'+target+'_attr_wrapper .attr').each(function() {
			    if(jQuery(this).val() !='')
				{
				
				gen_shortcode+= ' '+jQuery(this).attr('name')+'="'+jQuery(this).val()+'"';
				}
			});
		}
		
		gen_shortcode+= ']\n';
		
		if(jQuery('#'+target+'_content').length > 0)
  		{
  			gen_shortcode+= jQuery('#'+target+'_content').val()+'\n[/'+target+']\n';
  			
  			var repeat = jQuery('#'+target+'_content_repeat').val();
  			for (count=1;count<=repeat;count=count+1)
			{
				if(count<repeat)
				{
					gen_shortcode+= '['+target+']\n';
					gen_shortcode+= jQuery('#'+target+'_content').val()+'\n[/'+target+']\n';
				}
				else
				{
					gen_shortcode+= '['+target+'_last]\n';
					gen_shortcode+= jQuery('#'+target+'_content').val()+'\n[/'+target+'_last]';
				}
			}
  		}
  		
  		jQuery('#'+target+'_code').val(gen_shortcode);
	});
});
</script>

	<div style="padding:20px 10px 10px 10px">
	<?php
		if(!empty($shortcodes))
		{
	?>
			<strong>Select Shortcode:</strong>
			<select id="shortcode_select">
				<option value="">---Select---</option>
			
	<?php
			foreach($shortcodes as $shortcode_name => $shortcode)
			{
	?>
	
			<option value="<?php echo $shortcode_name; ?>"><?php echo $shortcode_name; ?></option>
	
	<?php
			}
	?>
			</select>
	<?php
		}
	?>
	
	<br/><br/>
	
	<?php
		if(!empty($shortcodes))
		{
			foreach($shortcodes as $shortcode_name => $shortcode)
			{
	?>
	
			<div id="div_<?php echo $shortcode_name; ?>" class="rm_section" style="display:none">
				<div class="rm_title">
					<h3><?php echo ucfirst($shortcode_name); ?></h3>
					<div class="clearfix"></div>
				</div>
				
				<div class="rm_text" style="padding: 10px 0 20px 0">
				
				<!-- img src="<?php echo $plugin_url.'/'.$shortcode_name.'.png'; ?>" alt=""/><br/><br/><br/ -->
				
				<?php
					if(isset($shortcode['content']) && $shortcode['content'])
					{
						if(isset($shortcode['content_text']))
						{
							$content_text = $shortcode['content_text'];
						}
						else
						{
							$content_text = 'Your Content';
						}
				?>
				
				<strong><?php echo $content_text; ?>:</strong><br/>
				<input type="hidden" id="<?php echo $shortcode_name; ?>_content_repeat" value="<?php echo $shortcode['repeat']; ?>"/>
				<textarea id="<?php echo $shortcode_name; ?>_content" style="width:100%;height:70px" rows="3" wrap="off"></textarea><br/><br/>
				
				<?php
					}
				?>
			
				<?php
					if(isset($shortcode['attr']) && !empty($shortcode['attr']))
					{
				?>
						
						<div id="<?php echo $shortcode_name; ?>_attr_wrapper">
						
				<?php
						foreach($shortcode['attr'] as $attr => $type)
						{
				?>
				
							<?php echo '<strong>'.ucfirst($attr).'</strong>: '.$shortcode['desc'][$attr]; ?><br/><br/>
							
							<?php
								switch($type)
								{
									case 'text':
							?>
							
									<input type="text" id="<?php echo $shortcode_name; ?>_text" style="width:100%" class="attr" name="<?php echo $attr; ?>"/>
							
							<?php
									break;
									
									case 'select':
							?>
							
									<select id="<?php echo $shortcode_name; ?>_select" style="width:25%" class="attr" name="<?php echo $attr; ?>">
									
										<?php
											if(isset($shortcode['options'][$attr]) && !empty($shortcode['options'][$attr]))
											{
												foreach($shortcode['options'][$attr] as $select_key => $option)
												{
										?>
										
													<option value="<?php echo $select_key; ?>"><?php echo $option; ?></option>
										
										<?php	
												}
											}
										?>							
									
									</select>
							
							<?php
									break;
									case 'checkbox':
							?>
							  		<input type="checkbox" id="<?php echo $shortcode_name; ?>_select" name="<?php echo $attr; ?>" value="false" />
							<?php
								 	break;
								}
							?>
							
							<br/><br/>
				
				<?php
						} //end attr foreach
				?>
				
						</div>
				
				<?php
					}
				?>
				<br/>
				
				<input type="button" id="<?php echo $shortcode_name; ?>" value="Generate Shortcode" class="button"/>
				
				<br/><br/><br/>
				
				<strong>Shortcode:</strong><br/>
				<textarea id="<?php echo $shortcode_name; ?>_code" style="width:90%;height:70px" rows="3" readonly="readonly" class="code_area" wrap="off"></textarea>
				
				</div>
				
			</div>
	
	<?php
			} //end shortcode foreach
		}
	?>
	
</div>

<?php

}

/*
	End Create Shortcode Generator Options
*/
function checkbox($value) {
			$checked = '';
			if (isset($this->saved_options[$value['id']])) {
				if ($this->saved_options[$value['id']] == true) {
					$checked = 'checked="checked"';
				}
			} elseif ($value['std'] == true) {
				$checked = 'checked="checked"';
			}
			
			echo '<tr valign="top"><th scope="row">' . $value['name'] . '</th><td>';
			echo '<input type="checkbox" name="' . $value['id'] . '" id="' . $value['id'] . '" value="true" ' . $checked . ' />';
			if(isset($value['desc'])){
				echo '<span class="checkbox-description">' . $value['desc'] . '</span>';
			}
			echo '</td></tr>';
		}
?>